package com.zhuzhe.blog.category.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhuzhe.blog.base.JsonData;
import com.zhuzhe.blog.base.ResponseData;
import com.zhuzhe.blog.category.entity.Label;
import com.zhuzhe.blog.category.requestDto.LabelDto;
import com.zhuzhe.blog.category.requestDto.LableSerachDto;
import com.zhuzhe.blog.category.responseVo.LabelPageVo;
import com.zhuzhe.blog.category.responseVo.LabelVo;
import com.zhuzhe.blog.category.service.ILabelService;
import com.zhuzhe.blog.convert.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 标签表 前端控制器
 * </p>
 *
 * @author u53
 * @since 2020-09-29
 */
@RestController
@RequestMapping("/label")
@Api(value = "标签管理接口", description = "标签管理接口，提供标签得的增、删、改、查")
public class LabelController {

    @Autowired
    private ILabelService labelService;

    @ApiOperation("根据标签名称与标签id查询标签列表接口")
    @PostMapping("/search") // 请求路径： localhost:9537/article/label/search
    public ResponseData<IPage<LabelPageVo>> search(@RequestBody LableSerachDto lableDto) {
        return labelService.queryPage(lableDto);
    }

    @ApiOperation("根据id查询标签")
    @ApiImplicitParam(name = "id", value = "标签id", required = true)
    @GetMapping("/{id}")
    public ResponseData<LabelVo> searchById(@PathVariable("id") String id) {
        return labelService.getLabelById(id);
    }

    @ApiOperation("修改标签")
    @PutMapping
    public ResponseData<String> updateLabelById(@RequestBody LabelDto labelDto) {
        Label label = new Label();
        Convert.convertType(labelDto,label);
        return labelService.updateLabelById(label);
    }

    @ApiOperation("新增标签信息")
    @PostMapping
    public ResponseData<String> save(@RequestBody  LabelDto labelDto) {
        Label label = new Label();
        Convert.convertType(labelDto,label);
        return labelService.saveLabel(label);
    }


    @ApiOperation("根据id删除标签")
    @ApiImplicitParam(name = "id", value = "类别id", required = true)
    @DeleteMapping("/{id}")
    public ResponseData<String> deleteById(@PathVariable("id") String id) {
        return labelService.removeLabelById(id);
    }

}
